package org.example.lease.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.lease.model.entities.PaymentType;
import org.example.lease.model.result.Result;
import org.example.lease.service.PaymentTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/14 13:15
 */
@RestController
@Slf4j
@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
public class PaymentTypeController {
    @Resource
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("/list")
    public Result<List<PaymentType>> queryAllPaymentType(){
        List<PaymentType> paymentTypes = paymentTypeService.queryAllPaymentType();
        return Result.ok(paymentTypes);
    }

    @Operation(summary = "更新或删除支付方式")
    @PostMapping("/saveOrUpdatePaymentType")
    public Result<String> saveOrUpdatePaymentType(@RequestBody PaymentType paymentType){
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok("更新成功");
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("/deleteById")
    public Result<?> deletePaymentById(@RequestParam Long id){
        paymentTypeService.removeById(id);
        return Result.ok();
    }

}
